/*
* Vector2.cpp
*
*  Created on: Jan 14, 2012
*  
*/


#include  "Vector2.h"
#include <math.h>

namespace Physics
{
#pragma region CONSTRUCTORs
	//C003: Copy Constructor
	Vector2::Vector2(const Vector2 &vec)
	{
		this->x = vec.getX();
		this->y = vec.getY();
	}
#pragma endregion


#pragma region PROPERTIES
	//M001: Setter X-value
	void Vector2::setX(const float &x) { this->x = x; }

	//M002: Getter X-value
	float Vector2::getX() const { return this->x; }

	//M003: Setter Y-value
	void Vector2::setY(const float &y) { this->y = y; }

	//M004: Getter Y-value
	float Vector2::getY() const { return this->y; }

	//M005: Setter XY-value
	void Vector2::setXY(const float &x, const float &y)
	{
		this->x = x;  this->y = y;
	}

	//M006: Setter XY-value
	void Vector2::setXY(const Vector2 &vec)
	{
		//*this = vec;
		this->x = vec.getX();
		this->y = vec.getY();
	}

	//M007: Getter XY-value
	const Vector2& Vector2::getXY() const
	{
		return (*this);
	}
#pragma endregion


#pragma region OVERLOADED-OPERATORs
	//M008: 
	const Vector2 Vector2::operator+(const Vector2 &vec)
	{
		return Vector2( (this->x + vec.getX()), (this->y + vec.getY()) );
	}

	//M009:
	const Vector2 Vector2::operator-(const Vector2 &vec)
	{
		return Vector2( (this->x - vec.getX()), (this->y - vec.getY()) );
	}

	//M010: 
	const Vector2 Vector2::operator*(const Vector2 &vec)
	{
		return Vector2( (this->x * vec.getX()), (this->y * vec.getY()) );
	}

	//M011: Assignment Operator
	const Vector2& Vector2::operator=(const Vector2 &vec)
	{
		if ( this != &vec ) //Check for NO self assignment
		{
			//Deallocate, allocate new space, copy values...
			this->x = vec.getX();
			this->y = vec.getY();
		}
		return *this;
	}

	//M012: 
	bool Vector2::operator==(const Vector2 &vec)
	{
		return (this->x == vec.getX() && this->y == vec.getY());
	}
#pragma endregion


#pragma region HELPER-METHODS
	//M014: Helper Method, Return ZERO-value 
	const Vector2 Vector2::zero() const
	{
		return Vector2();
	}
#pragma endregion

	float Vector2::findDistance(Vector2 const &vec)
	{
		// sqrt( ( vec.x - this.x )^2 + (vec.y - this.y )^2 )
		return sqrt( ( ( vec.getX() - this->x ) * (vec.getX() - this->x) ) +  ( ( vec.getY() - this->y ) *  (vec.getY() - this->y) ) );
	}
	
	float Vector2::dotProduct(Vector2 const &vec)
	{
		float tempX, tempY;

		tempX = this->x * vec.getX();
		tempY = this->y * vec.getY();

		return (tempX + tempY);
	}

	
	float Vector2::magnitude()
	{
		return sqrt( (this->x * this->x) + (this->y * this->y) );
	}

	void Vector2::normalize()
	{
		this->x = (this->x / magnitude() );
		this->y = (this->y / magnitude() ); 
	}
} /* NAMESPACE */